package com.ruoyi.customer.mapper;

import com.ruoyi.customer.api.domain.CustomerManagement;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 客户管理Mapper接口
 *
 * @author ruoyi
 * @date 2024-09-03
 */
public interface CustomerManagementMapper {
    /**
     * 查询客户管理
     *
     * @param id 客户管理主键
     * @return 客户管理
     */
    public CustomerManagement selectCustomerManagementById(Long id);
    /**
     * 查询客户管理
     *
     * @param phoneNumber 客户管理主键
     * @return 客户管理
     */
    public CustomerManagement selectCustomerManagementByPhoneNumber(String phoneNumber);

    /**
     * 查询客户管理列表
     *
     * @param customerManagement 客户管理
     * @return 客户管理集合
     */
    public List<CustomerManagement> selectCustomerManagementList(CustomerManagement customerManagement);

    /**
     * 新增客户管理
     *
     * @param customerManagement 客户管理
     * @return 结果
     */
    public int insertCustomerManagement(CustomerManagement customerManagement);

    /**
     * 修改客户管理
     *
     * @param customerManagement 客户管理
     * @return 结果
     */
    public int updateCustomerManagement(CustomerManagement customerManagement);

    /**
     * 删除客户管理
     *
     * @param id 客户管理主键
     * @return 结果
     */
    public int deleteCustomerManagementById(Long id);

    /**
     * 批量删除客户管理
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteCustomerManagementByIds(Long[] ids);

    @Select("select id, account from customer_management where account = #{account} and del_flag = '0' limit 1")
    CustomerManagement checkCustomerAccountUnique(String account);

    CustomerManagement selectCustomerByAccount(String account);

    /**
     * 通过手机号获取信息
     * @param phoneNumber
     * @return
     */
    @Select("select id, phone_number from customer_management where phone_number = #{phoneNumber} and del_flag = '0' limit 1")
    CustomerManagement checkPhoneUnique(String phoneNumber);

    /**
     * 校验email是否唯一
     * @param email 用户邮箱
     * @return 结果
     */
    @Select("select id, email from customer_management where email = #{email} and del_flag = '0' limit 1")
    CustomerManagement checkEmailUnique(String email);

    /**
     * 更新头像
     * @param account
     * @param avatar
     * @return
     */
    @Update("update customer_management set avatar = #{avatar} where account = #{account}")
    int updateCustomerAvatar(@Param("account")String account,@Param("avatar") String avatar);

    /**
     * 重置密码
     * @param account
     * @param password
     * @return
     */
    @Update("update customer_management set password = #{password} where account = #{account}")
    int resetCustomerPwd(@Param("account") String account,@Param("password") String password);

    /**
     * 根据openId查询用户信息
     * @param openId
     * @return
     */
    public CustomerManagement selectWxUserByOpenIdOrPhoneNumber(@Param("openId") String openId,@Param("phoneNumber") String phoneNumber);

    List<CustomerManagement>  selectUnBindCustomerList(CustomerManagement customerManagement);
}
